<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"
        >


<ui:component>
    <h:form id="queryDatabaseForm">
        <h:panelGroup layout="block">
             <!--opened="#{adminPageBean.result eq null}"-->
            <rich:simpleTogglePanel switchType="client"
                                    label="Query"

                    >

                <h:panelGrid columns="2" style="width:100%">
                    <h:inputText value="#{admin.query}" required="true" requiredMessage="Mora imati upit"
                                 style="font-size:15px; width:100%"/>
                    <!--<rich:fileUpload acceptedTypes="txt, sql" immediateUpload="true"/>-->
                    <a4j:commandButton id="run"
                                       value="Execute"
                                       action="#{admin.runQuery}"
                                       reRender="queryDatabaseForm"
                                       limitToList="true"
                            />
                </h:panelGrid>

            </rich:simpleTogglePanel>

        </h:panelGroup>
        <!--opened="#{adminPageBean.result ne null}"-->
        <h:panelGroup layout="block">
                <rich:simpleTogglePanel switchType="client"
                                        label="Results"
                                        >
                    <pre>
                        <h:outputText value="#{adminPageBean.result.message}"
                                       rendered="#{adminPageBean.result.textMessage}"/>
                    </pre>
                    <rich:extendedDataTable id="resultTable"
                                            value="#{adminPageBean.result.rows}"
                                            var="row"
                                            width="100%"
                                            rendered="#{not adminPageBean.result.textMessage}">

                        <rich:columns value="#{adminPageBean.result.columnNames}"
                                      var="name"
                                      index="ind">

                            <f:facet name="header">
                                <h:outputLabel value="#{name}"/>
                            </f:facet>

                            <h:outputText value="#{row[ind] eq null ? 'null' : row[ind]}"/>

                        </rich:columns>
                    </rich:extendedDataTable>
                </rich:simpleTogglePanel>
        </h:panelGroup>
    </h:form>
</ui:component>


</html>